<?php
require_once("lib/db_connection.php");
$company_id = $_SESSION['company_id'];
$p1 = $_GET['p1'];
$p2 = $_GET['p2'];
$p3 = $_GET['p3'];

if($p2=='LIKE')
$passed_where = $p1." ".$p2." '%".$p3."%'";
if($p2!='LIKE')
$passed_where = $p1." ".$p2." '".$p3."'";

if($p3=='')
{
$query_ins = "SELECT 
veh_insurance_dynamic_tbl.*,veh_insurance_dynamic_tbl.vehicle_id as v_num,
vehicle_tbl.*,vehicle_tbl.vehicle_id as r_id 
FROM veh_insurance_dynamic_tbl 
JOIN vehicle_tbl 
ON veh_insurance_dynamic_tbl.vehicle_id=vehicle_tbl.vehicle_id
WHERE veh_insurance_dynamic_tbl.company_id='".$company_id."'";
}

if($p3!='')
{
$query_ins = "SELECT 
veh_insurance_dynamic_tbl.*,veh_insurance_dynamic_tbl.vehicle_id as v_num,
vehicle_tbl.*,vehicle_tbl.vehicle_id as r_id 
FROM veh_insurance_dynamic_tbl 
JOIN vehicle_tbl 
ON veh_insurance_dynamic_tbl.vehicle_id=vehicle_tbl.vehicle_id
WHERE veh_insurance_dynamic_tbl.company_id='".$company_id."' AND ".$passed_where;	
}
$result_ins = mysql_query($query_ins)or die(mysql_error());
?>
<html>
<head>
<style type="text/css">
table,th,td
{
border:1.5px solid;
border-collapse:collapse;
}
</style>
<script type='text/javascript'>
function OpenExcel()
{
	var p1 = document.getElementById('p1').value;
	var p2 = document.getElementById('p2').value;
	var p3 = document.getElementById('p3').value;
	window.open('insurance_to_excel.php?p1='+p1+'&p2='+p2+'&p3='+p3,'SendToExcel');
}
</script>
</head>
<body>
<table width='100%' style='margin-left:auto;margin-right:auto;font-size:12px;font-family:Times New Roman'>
<tr>
		<th width='5%' rowspan='2' style="background-color:gray">Plate</th>
		<th width='5%' rowspan='2' style="background-color:gray">Year</th>
		<th width='10%' rowspan='2' style="background-color:gray">Make</th>
		<th width='10%' rowspan='2' style="background-color:gray">Model</th>
		<th width='10%' rowspan='2' style="background-color:gray">Policy No</th>
		<th width='10%' rowspan='2' style="background-color:gray">Insurance Company</th>
		<th width='10%' rowspan='2' style="background-color:gray">Intermediary</th>
		<th width='5%' rowspan='2' style="background-color:gray">Period of Cover</th>
		<th width='5%' rowspan='2' style="background-color:gray">Renewal Date</th>
		<th width='10%' rowspan='2' style="background-color:gray">Description</th>
		<th width='10%' colspan='7' style="background-color:gray">Sum Insured</th>
		<th width='10%' colspan='7' style="background-color:gray">Premium</th>
</tr>
		
<tr>	
		<th width='3%' colspan='1' style="background-color:gray">CTPL</th>
		<th width='3%' colspan='1' style="background-color:gray">OD</th>
		<th width='3%' colspan='1' style="background-color:gray">ELBI</th>
		<th width='3%' colspan='1' style="background-color:gray">ELPD</th>
		<th width='3%' colspan='1' style="background-color:gray">OtherCategory1</th>
		<th width='3%' colspan='1' style="background-color:gray">OtherCategory2</th>
		<th width='5%' colspan='1' style="background-color:gray">Total</th>
		
		<th width='3%' colspan='1' style="background-color:gray">CTPL</th>
		<th width='3%' colspan='1' style="background-color:gray">OD</th>
		<th width='3%' colspan='1' style="background-color:gray">ELBI</th>
		<th width='3%' colspan='1' style="background-color:gray">ELPD</th>
		<th width='3%' colspan='1' style="background-color:gray">OtherCategory1</th>
		<th width='3%' colspan='1' style="background-color:gray">OtherCategory2</th>
		<th width='5%' colspan='1' style="background-color:gray">Total</th>
</tr>
		
		<?php
		while($row_ins = mysql_fetch_array($result_ins))
		{
			//TRACKING
			/*$tracking = $row_fuel['track_by'];
			if($tracking=='distance')
			$curr_od = $row_fuel['miles'].'Km';
			if($tracking=='hours')
			$curr_od = $row_fuel['miles'].'Hrs';*/
			
		?>
		<tr>
			<!--INSURANCE-->
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["veh_num"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["year"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["manufacturer_name"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["model_name"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["policy_num"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["company"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["agent"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["cover_date"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["renewal_date"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["remarks"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["ctpl_amt"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["od_amt"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["elbi_amt"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["elpd_amt"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["other1_amt"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["other2_amt"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["tot_amt"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["ctpl_price"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["od_price"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["elbi_price"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["elpd_price"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["premium1_amt"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["premium2_amt"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_ins["tot_price"] ?>&nbsp;</td>
		</tr>
		<?php
		}
		?>
</table>
<br />
<input id="p1" type="hidden" value='<?php echo $p1 ?>' />
<input id="p2" type="hidden" value='<?php echo $p2 ?>' />
<input id="p3" type="hidden" value='<?php echo $p3 ?>' />
<input type="submit" value="Send to Excel" style='margin-left:auto;margin-right:auto;font-size:12px;font-family:Times New Roman' onClick=OpenExcel() />
</body>
</html>
		
